#include "widget.h"
#include "ui_widget.h"

#include <QPainter>
#include <QPen>
#include <QBrush>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    (void) event;
    //绘图工作就会放到这里来执行

    //创建绘画者对象
    QPainter painter(this);     //这里的this不是父对象,而是指定绘制的设备(往啥东西上画)

    //创建画笔对象
    QPen pen;
    //设置成红色的线条
    pen.setColor(QColor(255,0,0));
    //设置线条的粗细
    pen.setWidth(5);
    //设置线条的风格为虚线
    pen.setStyle(Qt::DashLine);
    //让painter对象应用pen
    painter.setPen(pen);

    //创建画刷对象
    QBrush brush;
    brush.setColor(QColor(0,255,0));
    brush.setStyle(Qt::CrossPattern);  //画刷默认风格是NoBrush(无填充)
    painter.setBrush(brush);

    //QFont font("微软雅黑",24);
    //painter.setFont(font);

    //画一个线段
    //painter.drawLine(20,20,200,20);
    //painter.drawLine(QPoint(20,100),QPoint(200,100));
    //painter.drawLine(20,20,20,300);
    //painter.drawLine(20,20,100,300);

    //画一个矩形
    //painter.drawRect(100,100,300,200);

    //画一个圆形
    painter.drawEllipse(100,100,400,400);

    //绘制文字
    //painter.drawText(0,100,"hello");
}

